#!/bin/bash

JLEXPATH="./JLexPHP"

if [ $# -ne 1 ]; then
    echo "Usage: `basename $0` {lexer_file}"
    exit 1
fi

FILENAME=$1

CLASSNAME=`grep %class $FILENAME | sed -e 's/%class //'`
if [ -z "$CLASSNAME" ]; then
    echo "Classname not found"
    exit
fi

LEXFILE=`realpath $1`

echo "Processing file: $LEXFILE"
echo "New file: $CLASSNAME.php"

cd $JLEXPATH

java JLexPHP.Main $LEXFILE

cd ../
mv $1.php ../../langs_code/system/$CLASSNAME.php

